package com.smh.demo1.a22;

import org.springframework.format.Formatter;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Locale;

/**
 * @author shiminghui
 * @date 2025/5/2 20:25
 * @description: TODO
 */
public class MyDateFormatter implements Formatter<LocalDateTime> {
    @Override
    public LocalDateTime parse(String text, Locale locale) throws ParseException {
        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.parse(text), LocalTime.of(0, 0));
        return localDateTime;
    }

    @Override
    public String print(LocalDateTime object, Locale locale) {
        if (object != null) {
            return object.toString();
        }
        return null;
    }
}
